package controllers

import (
	"fmt"
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/orm"
	"test/models"
)

type UserController struct {
	beego.Controller
}
type User struct {
	Id       int
	UserName string
}
func (c *UserController) Get() {
	//c.Ctx.WriteString("Hello world");
	c.Data["Website"] = "beego.me"
	c.Data["Email"] = "astaxie@gmail.com"
	c.TplName = "index.tpl"
}

func (this *UserController) GetInfo() {
	o := orm.NewOrm()
	user:=models.User{}
	user.Name = "ll"
	id,err := o.Insert(&user)
	if err != nil {
		fmt.Println("insert err")
		return
	}
	fmt.Println("cuss",id)
	//var users []User
	//num, err := o.Raw("SELECT id, user_name FROM user WHERE id = ?", 1).QueryRows(&users)
	//if err == nil {
	//	fmt.Println("user nums: ", num)
	//}
	//fmt.Println(users)
	//id := this.Ctx.Input.Param(":id");
	//id := this.GetString("id")
	//pkgname := this.GetString("pkgname")
	//content := this.GetString("content")
	//this.Ctx.WriteString("this id = "+ id+"pkgname="+pkgname+"content"+content);
}
func (this *UserController) PostInfo() {
	o := orm.NewOrm()
	var users []User
	num, err := o.Raw("SELECT id, user_name FROM user WHERE id = ?", 1).QueryRows(&users)
	if err == nil {
		fmt.Println("user nums: ", num)
	}
	//id := this.Ctx.Input.Param(":id");
	id := this.GetString("id")
	//return id;
	//pkgname := this.GetString("pkgname")
	//content := this.GetString("content")
	this.Ctx.WriteString("this id = "+ id);
}